﻿using mvcDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using System.Web;

namespace mvcDemo.Controllers
{
    public class TypesController : ApiController
    {

        // GET api/types
        /// <summary>
        /// 获取所有证件类型
        /// </summary>
        /// <returns></returns>
        public JsonMessage Get()
        {
            try
            {
                using (Entities db = new Entities())
                {
                    List<TYPE> types = db.TYPE.ToList();                
                    return new JsonMessage(types);
                }
            }
            catch (Exception ex)
            {
                return new JsonMessage("获取证件类型失败！", ex.Message, ex.StackTrace);
            }
        }

        // GET api/types/5
        /// <summary>
        /// 获取指定的证件类型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonMessage Get(int id)
        {
            try
            {
                using (Entities db = new Entities())
                {
                    TYPE type = db.TYPE.Find(id);
                    return new JsonMessage(type);
                }
            }
            catch (Exception ex)
            {
                return new JsonMessage("获取相片失败！", ex.Message, ex.StackTrace);
            }
        }

    }
}
